using Godot;
using System;

public partial class HUD : CanvasLayer
{

	[Signal]
	public delegate void StartGameEventHandler();

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
	}

	public void ShowMassge(String text)
	{
        Label message = this.GetNode<Label>("Message");
		message.Text = text;
		message.Show();
		
		this.GetNode<Timer>("MessageTimer").Start();
	}

	async public void ShowGameOver()
	{
		// 设置游戏结束文案
		ShowMassge("Game Over");

        Timer messageTimer = this.GetNode<Timer>("MessageTimer");
		await ToSignal(messageTimer, Timer.SignalName.Timeout);

        Label message = this.GetNode<Label>("Message");
		message.Text = "Dodge the Creeps!";
		message.Show();

		await ToSignal(GetTree().CreateTimer(1.0), SceneTreeTimer.SignalName.Timeout);
		// 显示开始按钮
		this.GetNode<Button>("StartButton").Show();

	}

	public void UpdateScore(int score)
	{
        Label scoreLabel = this.GetNode<Label>("ScoreLabel");
		scoreLabel.Text = score.ToString();
	}

	public void OnMessageTimerTimeout()
	{
		this.GetNode<Label>("Message").Hide();
	}

	public void OnStartButtonPressed() 
	{
        this.GetNode<Button>("StartButton").Hide();
        EmitSignal(SignalName.StartGame);
    }

}
